Imports System.IO

Imports Phoenix.DataAccess
Imports Phoenix.Events
Imports Phoenix.Helpers
Imports Phoenix.Preferences

Namespace Forms

    Public Class ClientForm : Inherits ChildFormBase

#Region " CategoryFormatter Class "
        Public Class CategoryFormatter : Implements IFormatProvider, ICustomFormatter
            Public Function GetFormat(ByVal type As System.Type) As Object Implements IFormatProvider.GetFormat
                Return Me
            End Function

            Public Function Format(ByVal formatString As String, ByVal arg As Object, ByVal formatProvider As IFormatProvider) As String Implements ICustomFormatter.Format
                Dim e As String = CType(arg, String)
                If e = "P" Then
                    Return Res.TypeProductDocument
                Else
                    Return Res.TypeServiceDocument
                End If
            End Function
        End Class
#end region

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            BHOperatorColumn.DisplayFormat.Format = New Lookup.EmployeeLookupFormatter
            BDCategoryColumn.DisplayFormat.Format = New CategoryFormatter
            AHServiceColumn.DisplayFormat.Format = New Lookup.ServiceLookupFormatter
            AHPerformerColumn.DisplayFormat.Format = New Lookup.EmployeeLookupFormatter
            AHOperatorColumn.DisplayFormat.Format = New Lookup.EmployeeLookupFormatter
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
        Friend WithEvents GeneralTabPage As System.Windows.Forms.TabPage
        Friend WithEvents PhoneBox As DevExpress.XtraEditors.TextEdit
        Friend WithEvents PhoneLabel As System.Windows.Forms.Label
        Friend WithEvents AddressMemo As DevExpress.XtraEditors.MemoEdit
        Friend WithEvents NameBox As DevExpress.XtraEditors.TextEdit
        Friend WithEvents CommentMemo As DevExpress.XtraEditors.MemoEdit
        Friend WithEvents InOfficeCheckBox As DevExpress.XtraEditors.CheckEdit
        Friend WithEvents TabControl As System.Windows.Forms.TabControl
        Friend WithEvents BirthDateEdit As DevExpress.XtraEditors.DateEdit
        Friend WithEvents BHGrid As DevExpress.XtraGrid.GridControl
        Friend WithEvents BHView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents BHTab As System.Windows.Forms.TabPage
        Friend WithEvents BDView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents BHDateColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BHAmountColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BHOperatorColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BDIconColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BDIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents BDCategoryColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BDTitleColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents BDPrice As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHGrid As DevExpress.XtraGrid.GridControl
        Friend WithEvents AHTab As System.Windows.Forms.TabPage
        Friend WithEvents AHView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents AHDescriptionColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHServiceColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHPerformerColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHStartTimeColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHFinishTimeColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHPriceColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHDateColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHStatusColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHCommentColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHCommentRI As DevExpress.XtraEditors.Repository.RepositoryItemMemoExEdit
        Friend WithEvents AHIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents AHIconColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHOperatorColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents lblName As System.Windows.Forms.Label
        Friend WithEvents lblGender As System.Windows.Forms.Label
        Friend WithEvents GenderEdit As DevExpress.XtraEditors.ComboBoxEdit
        Friend WithEvents lblEmail As System.Windows.Forms.Label
        Friend WithEvents lblAddress As System.Windows.Forms.Label
        Friend WithEvents lblBirthday As System.Windows.Forms.Label
        Friend WithEvents EmailBox As DevExpress.XtraEditors.ButtonEdit

        Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ClientForm))
            Me.TabControl = New System.Windows.Forms.TabControl
            Me.GeneralTabPage = New System.Windows.Forms.TabPage
            Me.EmailBox = New DevExpress.XtraEditors.ButtonEdit
            Me.lblEmail = New System.Windows.Forms.Label
            Me.GenderEdit = New DevExpress.XtraEditors.ComboBoxEdit
            Me.lblGender = New System.Windows.Forms.Label
            Me.BirthDateEdit = New DevExpress.XtraEditors.DateEdit
            Me.PhoneBox = New DevExpress.XtraEditors.TextEdit
            Me.PhoneLabel = New System.Windows.Forms.Label
            Me.AddressMemo = New DevExpress.XtraEditors.MemoEdit
            Me.lblAddress = New System.Windows.Forms.Label
            Me.lblBirthday = New System.Windows.Forms.Label
            Me.lblName = New System.Windows.Forms.Label
            Me.CommentMemo = New DevExpress.XtraEditors.MemoEdit
            Me.InOfficeCheckBox = New DevExpress.XtraEditors.CheckEdit
            Me.NameBox = New DevExpress.XtraEditors.TextEdit
            Me.AHTab = New System.Windows.Forms.TabPage
            Me.AHGrid = New DevExpress.XtraGrid.GridControl
            Me.AHView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.AHIconColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.AHDescriptionColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHServiceColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHPerformerColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHDateColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHStartTimeColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHFinishTimeColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHPriceColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHStatusColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHOperatorColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHCommentColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHCommentRI = New DevExpress.XtraEditors.Repository.RepositoryItemMemoExEdit
            Me.BHTab = New System.Windows.Forms.TabPage
            Me.BHGrid = New DevExpress.XtraGrid.GridControl
            Me.BDView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.BDIconColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BDIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.BDCategoryColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BDTitleColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BDPrice = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BHView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.BHDateColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BHAmountColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.BHOperatorColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.TabControl.SuspendLayout()
            Me.GeneralTabPage.SuspendLayout()
            CType(Me.EmailBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.GenderEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.BirthDateEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.PhoneBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AddressMemo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.CommentMemo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.InOfficeCheckBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.NameBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.AHTab.SuspendLayout()
            CType(Me.AHGrid, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHCommentRI, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.BHTab.SuspendLayout()
            CType(Me.BHGrid, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.BDView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.BDIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.BHView, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'TabControl
            '
            Me.TabControl.Controls.Add(Me.GeneralTabPage)
            Me.TabControl.Controls.Add(Me.AHTab)
            Me.TabControl.Controls.Add(Me.BHTab)
            Me.TabControl.Dock = System.Windows.Forms.DockStyle.Fill
            Me.TabControl.Location = New System.Drawing.Point(0, 49)
            Me.TabControl.Name = "TabControl"
            Me.TabControl.SelectedIndex = 0
            Me.TabControl.Size = New System.Drawing.Size(664, 421)
            Me.TabControl.TabIndex = 4
            Me.TabControl.TabStop = False
            '
            'GeneralTabPage
            '
            Me.GeneralTabPage.Controls.Add(Me.EmailBox)
            Me.GeneralTabPage.Controls.Add(Me.lblEmail)
            Me.GeneralTabPage.Controls.Add(Me.GenderEdit)
            Me.GeneralTabPage.Controls.Add(Me.lblGender)
            Me.GeneralTabPage.Controls.Add(Me.BirthDateEdit)
            Me.GeneralTabPage.Controls.Add(Me.PhoneBox)
            Me.GeneralTabPage.Controls.Add(Me.PhoneLabel)
            Me.GeneralTabPage.Controls.Add(Me.AddressMemo)
            Me.GeneralTabPage.Controls.Add(Me.lblAddress)
            Me.GeneralTabPage.Controls.Add(Me.lblBirthday)
            Me.GeneralTabPage.Controls.Add(Me.lblName)
            Me.GeneralTabPage.Controls.Add(Me.CommentMemo)
            Me.GeneralTabPage.Controls.Add(Me.InOfficeCheckBox)
            Me.GeneralTabPage.Controls.Add(Me.NameBox)
            Me.GeneralTabPage.Location = New System.Drawing.Point(4, 22)
            Me.GeneralTabPage.Name = "GeneralTabPage"
            Me.GeneralTabPage.Size = New System.Drawing.Size(656, 395)
            Me.GeneralTabPage.TabIndex = 0
            Me.GeneralTabPage.Text = "General"
            '
            'EmailBox
            '
            Me.EmailBox.EditValue = ""
            Me.EmailBox.Location = New System.Drawing.Point(112, 144)
            Me.EmailBox.Name = "EmailBox"
            '
            'EmailBox.Properties
            '
            Me.EmailBox.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton})
            Me.EmailBox.Size = New System.Drawing.Size(176, 20)
            Me.EmailBox.TabIndex = 10
            '
            'lblEmail
            '
            Me.lblEmail.Location = New System.Drawing.Point(16, 146)
            Me.lblEmail.Name = "lblEmail"
            Me.lblEmail.Size = New System.Drawing.Size(88, 16)
            Me.lblEmail.TabIndex = 9
            Me.lblEmail.Text = "Email:"
            '
            'GenderEdit
            '
            Me.GenderEdit.EditValue = ""
            Me.GenderEdit.Location = New System.Drawing.Point(112, 72)
            Me.GenderEdit.Name = "GenderEdit"
            '
            'GenderEdit.Properties
            '
            Me.GenderEdit.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.GenderEdit.Properties.Items.AddRange(New Object() {"Male", "Female"})
            Me.GenderEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
            Me.GenderEdit.Size = New System.Drawing.Size(176, 20)
            Me.GenderEdit.TabIndex = 4
            '
            'lblGender
            '
            Me.lblGender.Location = New System.Drawing.Point(16, 74)
            Me.lblGender.Name = "lblGender"
            Me.lblGender.Size = New System.Drawing.Size(88, 16)
            Me.lblGender.TabIndex = 3
            Me.lblGender.Text = "Gender:"
            '
            'BirthDateEdit
            '
            Me.BirthDateEdit.EditValue = New Date(2005, 4, 20, 0, 0, 0, 0)
            Me.BirthDateEdit.Location = New System.Drawing.Point(112, 96)
            Me.BirthDateEdit.Name = "BirthDateEdit"
            '
            'BirthDateEdit.Properties
            '
            Me.BirthDateEdit.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.BirthDateEdit.Size = New System.Drawing.Size(176, 20)
            Me.BirthDateEdit.TabIndex = 6
            '
            'PhoneBox
            '
            Me.PhoneBox.EditValue = ""
            Me.PhoneBox.Location = New System.Drawing.Point(112, 120)
            Me.PhoneBox.Name = "PhoneBox"
            Me.PhoneBox.Size = New System.Drawing.Size(176, 20)
            Me.PhoneBox.TabIndex = 8
            '
            'PhoneLabel
            '
            Me.PhoneLabel.Location = New System.Drawing.Point(16, 122)
            Me.PhoneLabel.Name = "PhoneLabel"
            Me.PhoneLabel.Size = New System.Drawing.Size(88, 16)
            Me.PhoneLabel.TabIndex = 7
            Me.PhoneLabel.Text = "Phone:"
            '
            'AddressMemo
            '
            Me.AddressMemo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
            Me.AddressMemo.EditValue = ""
            Me.AddressMemo.Location = New System.Drawing.Point(16, 192)
            Me.AddressMemo.Name = "AddressMemo"
            Me.AddressMemo.Size = New System.Drawing.Size(272, 184)
            Me.AddressMemo.TabIndex = 12
            '
            'lblAddress
            '
            Me.lblAddress.Location = New System.Drawing.Point(16, 176)
            Me.lblAddress.Name = "lblAddress"
            Me.lblAddress.Size = New System.Drawing.Size(88, 16)
            Me.lblAddress.TabIndex = 11
            Me.lblAddress.Text = "Address :"
            '
            'lblBirthday
            '
            Me.lblBirthday.Location = New System.Drawing.Point(16, 98)
            Me.lblBirthday.Name = "lblBirthday"
            Me.lblBirthday.Size = New System.Drawing.Size(88, 16)
            Me.lblBirthday.TabIndex = 5
            Me.lblBirthday.Text = "Birthday:"
            '
            'lblName
            '
            Me.lblName.Location = New System.Drawing.Point(16, 18)
            Me.lblName.Name = "lblName"
            Me.lblName.Size = New System.Drawing.Size(88, 16)
            Me.lblName.TabIndex = 0
            Me.lblName.Text = "Name:"
            '
            'CommentMemo
            '
            Me.CommentMemo.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.CommentMemo.EditValue = ""
            Me.CommentMemo.Location = New System.Drawing.Point(304, 16)
            Me.CommentMemo.Name = "CommentMemo"
            Me.CommentMemo.Size = New System.Drawing.Size(336, 365)
            Me.CommentMemo.TabIndex = 13
            '
            'InOfficeCheckBox
            '
            Me.InOfficeCheckBox.Location = New System.Drawing.Point(112, 40)
            Me.InOfficeCheckBox.Name = "InOfficeCheckBox"
            '
            'InOfficeCheckBox.Properties
            '
            Me.InOfficeCheckBox.Properties.Caption = "In salon"
            Me.InOfficeCheckBox.Size = New System.Drawing.Size(88, 19)
            Me.InOfficeCheckBox.TabIndex = 2
            '
            'NameBox
            '
            Me.NameBox.EditValue = ""
            Me.NameBox.Location = New System.Drawing.Point(112, 16)
            Me.NameBox.Name = "NameBox"
            Me.NameBox.Size = New System.Drawing.Size(176, 20)
            Me.NameBox.TabIndex = 1
            '
            'AHTab
            '
            Me.AHTab.Controls.Add(Me.AHGrid)
            Me.AHTab.Location = New System.Drawing.Point(4, 22)
            Me.AHTab.Name = "AHTab"
            Me.AHTab.Size = New System.Drawing.Size(656, 395)
            Me.AHTab.TabIndex = 2
            Me.AHTab.Text = "Appointments"
            '
            'AHGrid
            '
            Me.AHGrid.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'AHGrid.EmbeddedNavigator
            '
            Me.AHGrid.EmbeddedNavigator.Name = ""
            Me.AHGrid.Location = New System.Drawing.Point(0, 0)
            Me.AHGrid.MainView = Me.AHView
            Me.AHGrid.Name = "AHGrid"
            Me.AHGrid.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.AHCommentRI, Me.AHIconRI})
            Me.AHGrid.Size = New System.Drawing.Size(656, 395)
            Me.AHGrid.TabIndex = 0
            Me.AHGrid.Text = "GridControl1"
            '
            'AHView
            '
            Me.AHView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.AHIconColumn, Me.AHDescriptionColumn, Me.AHServiceColumn, Me.AHPerformerColumn, Me.AHDateColumn, Me.AHStartTimeColumn, Me.AHFinishTimeColumn, Me.AHPriceColumn, Me.AHStatusColumn, Me.AHOperatorColumn, Me.AHCommentColumn})
            Me.AHView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
            Me.AHView.GridControl = Me.AHGrid
            Me.AHView.GroupFormat = "{1}"
            Me.AHView.Name = "AHView"
            Me.AHView.OptionsView.ShowGroupPanel = False
            Me.AHView.OptionsView.ShowIndicator = False
            Me.AHView.OptionsView.ShowVertLines = False
            '
            'AHIconColumn
            '
            Me.AHIconColumn.ColumnEdit = Me.AHIconRI
            Me.AHIconColumn.Name = "AHIconColumn"
            Me.AHIconColumn.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHIconColumn.VisibleIndex = 0
            Me.AHIconColumn.Width = 20
            '
            'AHIconRI
            '
            Me.AHIconRI.AutoHeight = False
            Me.AHIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.AHIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", Nothing, 8)})
            Me.AHIconRI.Name = "AHIconRI"
            '
            'AHDescriptionColumn
            '
            Me.AHDescriptionColumn.Caption = "Description"
            Me.AHDescriptionColumn.FieldName = "Description"
            Me.AHDescriptionColumn.Name = "AHDescriptionColumn"
            Me.AHDescriptionColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHDescriptionColumn.VisibleIndex = 1
            Me.AHDescriptionColumn.Width = 69
            '
            'AHServiceColumn
            '
            Me.AHServiceColumn.Caption = "Service"
            Me.AHServiceColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHServiceColumn.FieldName = "ServiceID"
            Me.AHServiceColumn.Name = "AHServiceColumn"
            Me.AHServiceColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHServiceColumn.VisibleIndex = 2
            Me.AHServiceColumn.Width = 69
            '
            'AHPerformerColumn
            '
            Me.AHPerformerColumn.Caption = "Staff member"
            Me.AHPerformerColumn.FieldName = "PerformerID"
            Me.AHPerformerColumn.Name = "AHPerformerColumn"
            Me.AHPerformerColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHPerformerColumn.VisibleIndex = 3
            Me.AHPerformerColumn.Width = 69
            '
            'AHDateColumn
            '
            Me.AHDateColumn.Caption = "Date"
            Me.AHDateColumn.DisplayFormat.FormatString = "d"
            Me.AHDateColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHDateColumn.FieldName = "StartTime"
            Me.AHDateColumn.Name = "AHDateColumn"
            Me.AHDateColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHDateColumn.VisibleIndex = 4
            Me.AHDateColumn.Width = 69
            '
            'AHStartTimeColumn
            '
            Me.AHStartTimeColumn.Caption = "Started At"
            Me.AHStartTimeColumn.DisplayFormat.FormatString = "t"
            Me.AHStartTimeColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHStartTimeColumn.FieldName = "StartTime"
            Me.AHStartTimeColumn.Name = "AHStartTimeColumn"
            Me.AHStartTimeColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHStartTimeColumn.VisibleIndex = 5
            Me.AHStartTimeColumn.Width = 69
            '
            'AHFinishTimeColumn
            '
            Me.AHFinishTimeColumn.Caption = "Finished At"
            Me.AHFinishTimeColumn.DisplayFormat.FormatString = "t"
            Me.AHFinishTimeColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHFinishTimeColumn.FieldName = "FinishTime"
            Me.AHFinishTimeColumn.Name = "AHFinishTimeColumn"
            Me.AHFinishTimeColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHFinishTimeColumn.VisibleIndex = 6
            Me.AHFinishTimeColumn.Width = 69
            '
            'AHPriceColumn
            '
            Me.AHPriceColumn.Caption = "Price"
            Me.AHPriceColumn.DisplayFormat.FormatString = "c2"
            Me.AHPriceColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
            Me.AHPriceColumn.FieldName = "ServiceCost"
            Me.AHPriceColumn.Name = "AHPriceColumn"
            Me.AHPriceColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHPriceColumn.VisibleIndex = 7
            Me.AHPriceColumn.Width = 69
            '
            'AHStatusColumn
            '
            Me.AHStatusColumn.Caption = "Status"
            Me.AHStatusColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHStatusColumn.Name = "AHStatusColumn"
            Me.AHStatusColumn.Options = CType((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHStatusColumn.VisibleIndex = 8
            Me.AHStatusColumn.Width = 69
            '
            'AHOperatorColumn
            '
            Me.AHOperatorColumn.Caption = "Operator"
            Me.AHOperatorColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHOperatorColumn.FieldName = "OperatorID"
            Me.AHOperatorColumn.Name = "AHOperatorColumn"
            Me.AHOperatorColumn.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHOperatorColumn.VisibleIndex = 9
            '
            'AHCommentColumn
            '
            Me.AHCommentColumn.Caption = "Comment"
            Me.AHCommentColumn.ColumnEdit = Me.AHCommentRI
            Me.AHCommentColumn.FieldName = "Comment"
            Me.AHCommentColumn.Name = "AHCommentColumn"
            Me.AHCommentColumn.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHCommentColumn.VisibleIndex = 10
            Me.AHCommentColumn.Width = 82
            '
            'AHCommentRI
            '
            Me.AHCommentRI.AutoHeight = False
            Me.AHCommentRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.AHCommentRI.Name = "AHCommentRI"
            '
            'BHTab
            '
            Me.BHTab.Controls.Add(Me.BHGrid)
            Me.BHTab.Location = New System.Drawing.Point(4, 22)
            Me.BHTab.Name = "BHTab"
            Me.BHTab.Size = New System.Drawing.Size(656, 395)
            Me.BHTab.TabIndex = 3
            Me.BHTab.Text = "Bill History"
            '
            'BHGrid
            '
            Me.BHGrid.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'BHGrid.EmbeddedNavigator
            '
            Me.BHGrid.EmbeddedNavigator.Name = ""
            Me.BHGrid.LevelDefaults.Add("Details", Me.BDView)
            Me.BHGrid.Location = New System.Drawing.Point(0, 0)
            Me.BHGrid.MainView = Me.BHView
            Me.BHGrid.Name = "BHGrid"
            Me.BHGrid.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.BDIconRI})
            Me.BHGrid.Size = New System.Drawing.Size(656, 395)
            Me.BHGrid.TabIndex = 0
            Me.BHGrid.Text = "BHGrid"
            '
            'BDView
            '
            Me.BDView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.BDIconColumn, Me.BDCategoryColumn, Me.BDTitleColumn, Me.BDPrice})
            Me.BDView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
            Me.BDView.GridControl = Me.BHGrid
            Me.BDView.GroupFormat = "{1} "
            Me.BDView.Name = "BDView"
            Me.BDView.OptionsBehavior.Editable = False
            Me.BDView.OptionsView.ShowGroupPanel = False
            Me.BDView.OptionsView.ShowIndicator = False
            Me.BDView.OptionsView.ShowVertLines = False
            '
            'BDIconColumn
            '
            Me.BDIconColumn.ColumnEdit = Me.BDIconRI
            Me.BDIconColumn.FieldName = "Category"
            Me.BDIconColumn.Name = "BDIconColumn"
            Me.BDIconColumn.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.BDIconColumn.VisibleIndex = 0
            Me.BDIconColumn.Width = 20
            '
            'BDIconRI
            '
            Me.BDIconRI.AutoHeight = False
            Me.BDIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.BDIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "S", 5), New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "P", 6)})
            Me.BDIconRI.Name = "BDIconRI"
            '
            'BDCategoryColumn
            '
            Me.BDCategoryColumn.Caption = "Category"
            Me.BDCategoryColumn.FieldName = "Category"
            Me.BDCategoryColumn.Name = "BDCategoryColumn"
            Me.BDCategoryColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.BDCategoryColumn.VisibleIndex = 1
            '
            'BDTitleColumn
            '
            Me.BDTitleColumn.Caption = "Title"
            Me.BDTitleColumn.FieldName = "Info"
            Me.BDTitleColumn.Name = "BDTitleColumn"
            Me.BDTitleColumn.VisibleIndex = 2
            '
            'BDPrice
            '
            Me.BDPrice.Caption = "Price"
            Me.BDPrice.DisplayFormat.FormatString = "c2"
            Me.BDPrice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
            Me.BDPrice.FieldName = "Cost"
            Me.BDPrice.Name = "BDPrice"
            Me.BDPrice.VisibleIndex = 3
            '
            'BHView
            '
            Me.BHView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.BHDateColumn, Me.BHAmountColumn, Me.BHOperatorColumn})
            Me.BHView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
            Me.BHView.GridControl = Me.BHGrid
            Me.BHView.GroupFormat = "{1}"
            Me.BHView.Name = "BHView"
            Me.BHView.OptionsBehavior.Editable = False
            Me.BHView.OptionsView.ShowGroupPanel = False
            Me.BHView.OptionsView.ShowIndicator = False
            Me.BHView.OptionsView.ShowVertLines = False
            '
            'BHDateColumn
            '
            Me.BHDateColumn.Caption = "Date/Time"
            Me.BHDateColumn.DisplayFormat.FormatString = "d"
            Me.BHDateColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.BHDateColumn.FieldName = "CreationTime"
            Me.BHDateColumn.Name = "BHDateColumn"
            Me.BHDateColumn.SortIndex = 0
            Me.BHDateColumn.SortOrder = DevExpress.Data.ColumnSortOrder.Descending
            Me.BHDateColumn.VisibleIndex = 0
            '
            'BHAmountColumn
            '
            Me.BHAmountColumn.Caption = "Amount"
            Me.BHAmountColumn.DisplayFormat.FormatString = "c2"
            Me.BHAmountColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
            Me.BHAmountColumn.FieldName = "PaymentSumm"
            Me.BHAmountColumn.Name = "BHAmountColumn"
            Me.BHAmountColumn.VisibleIndex = 1
            '
            'BHOperatorColumn
            '
            Me.BHOperatorColumn.Caption = "Operator"
            Me.BHOperatorColumn.FieldName = "OperatorID"
            Me.BHOperatorColumn.Name = "BHOperatorColumn"
            Me.BHOperatorColumn.VisibleIndex = 2
            '
            'ClientForm
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(664, 470)
            Me.Controls.Add(Me.TabControl)
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.Name = "ClientForm"
            Me.Text = "New Client"
            Me.Controls.SetChildIndex(Me.TabControl, 0)
            Me.TabControl.ResumeLayout(False)
            Me.GeneralTabPage.ResumeLayout(False)
            CType(Me.EmailBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.GenderEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.BirthDateEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.PhoneBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AddressMemo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.CommentMemo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.InOfficeCheckBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.NameBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.AHTab.ResumeLayout(False)
            CType(Me.AHGrid, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHCommentRI, System.ComponentModel.ISupportInitialize).EndInit()
            Me.BHTab.ResumeLayout(False)
            CType(Me.BHGrid, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.BDView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.BDIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.BHView, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub
#End Region

#Region " Event Handlers "
        Private Sub ClientForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            BHGrid.LevelDefaults.Add("BillBillDetail", BDView)

            UpdateConfiguration()
            UpdateSecurityEditCommands()
        End Sub

        Private Sub EmailBox_ButtonClick(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles EmailBox.ButtonClick
            If EmailBox.Text.Trim() <> String.Empty Then
                System.Diagnostics.Process.Start("mailto:" & EmailBox.Text)
            End If
        End Sub
#End Region

#Region " Data "
        Public Shadows Property DataSource() As DataSetData.Client
            Get
                Return CType(MyBase.DataSource, DataSetData.Client)
            End Get
            Set(ByVal Value As DataSetData.Client)
                MyBase.DataSource = Value
            End Set
        End Property

        Protected Overrides Sub DoBinding()
            CommentMemo.DataBindings.Add("Text", DataSource, "Comment")
            AddressMemo.DataBindings.Add("Text", DataSource, "Address")
            PhoneBox.DataBindings.Add("Text", DataSource, "Phone")
            EmailBox.DataBindings.Add("Text", DataSource, "Email")
            InOfficeCheckBox.DataBindings.Add("Checked", DataSource, "InOffice")


            BindWithCapitalization(NameBox, "Text", DataSource, "FullName")

            Dim bindBirthDay As New Binding("EditValue", DataSource, "BirthDate")
            AddHandler bindBirthDay.Format, AddressOf String2DateTime
            AddHandler bindBirthDay.Parse, AddressOf DateTime2String
            BirthDateEdit.DataBindings.Add(bindBirthDay)

            Dim genderBinding As New Binding("Text", DataSource, "Gender")
            AddHandler genderBinding.Format, AddressOf Gender2String
            AddHandler genderBinding.Parse, AddressOf String2Gender
            GenderEdit.DataBindings.Add(genderBinding)




            BHValid = False
            AHValid = False

            TabControl.SelectedIndex = 0
            NameBox.Focus()
        End Sub


        Private Sub String2Gender(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If args.Value.Equals("Female") Then
                args.Value = "F"
            Else
                args.Value = "M"
            End If
        End Sub

        Private Sub Gender2String(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If args.Value.Equals("F") Then
                args.Value = "Female"
            Else
                args.Value = "Male"
            End If
        End Sub

        Private Sub String2DateTime(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If Not args.DesiredType Is GetType(DateTime) Then
                Exit Sub
            End If

            If Not args.Value Is Nothing Then
                If CType(args.Value, String).Length = 0 Then
                    args.Value = DBNull.Value
                Else
                    Try
                        args.Value = DateTime.Parse(args.Value.ToString)
                    Catch
                        args.Value = DBNull.Value
                    End Try
                End If
            Else
                args.Value = DBNull.Value
            End If
        End Sub
        Private Sub DateTime2String(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If Not args.DesiredType Is GetType(String) Then
                Exit Sub
            End If

            If Not args.Value Is DBNull.Value Then
                args.Value = args.Value.ToShortDateString
            Else
                args.Value = String.Empty
            End If
        End Sub

        Private Sub Checked2Byte(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If Not args.DesiredType Is GetType(Boolean) Then
                Exit Sub
            End If

            args.Value = IIf(args.Value = 1, True, False)
        End Sub
        Private Sub Byte2Checked(ByVal sender As Object, ByVal args As ConvertEventArgs)
            If Not args.DesiredType Is GetType(Byte) Then
                Exit Sub
            End If

            args.Value = IIf(args.Value = True, 1, 0)
        End Sub

        Public Overrides ReadOnly Property DocumentTitle() As String
            Get
                Return DataSource.FullName()
            End Get
        End Property

        Public Overrides ReadOnly Property DocumentType() As String
            Get
                Return Res.TypeClientDocument
            End Get
        End Property
#End Region

#Region " Appointments & Bills "
        Private mBHValid As Boolean = False

        Private Property BHValid() As Boolean
            Get
                If BHGrid.DataSource Is Nothing Then Return False
                Return mBHValid
            End Get
            Set(ByVal Value As Boolean)
                If Not Value Then
                    BHGrid.DataSource = Nothing
                End If
                mBHValid = Value
            End Set
        End Property


        Private mAHValid As Boolean = False
        Private Property AHValid() As Boolean
            Get
                If AHGrid.DataSource Is Nothing Then Return False
                Return mAHValid
            End Get
            Set(ByVal Value As Boolean)
                If Not Value Then
                    AHGrid.DataSource = Nothing
                End If
                mAHValid = Value
            End Set
        End Property



        Private Sub TabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged
            If TabControl.SelectedTab Is BHTab Then
                LoadBillHistory()
            ElseIf TabControl.SelectedTab Is AHTab Then
                LoadAppointmentHistory()
            End If
        End Sub

        Private Sub LoadBillHistory()
            If BHValid = True Then Return
            If DataSource.RowState = DataRowState.Detached Then Return

            BHGrid.DataSource = AppDataLayer.GetBillHistory(DataSource.ClientID).Bills

            mBHValid = True
        End Sub

        Private Sub UpdateBillHistory()
            If BHValid Then
                BHValid = False
                If TabControl.SelectedTab Is BHTab Then
                    LoadBillHistory()
                End If
            End If
        End Sub


        Private Sub LoadAppointmentHistory()
            If AHValid = True Then Return
            If DataSource.RowState = DataRowState.Detached Then Return

            AHGrid.DataSource = AppDataLayer.GetClientAppointments(DataSource.ClientID).Appointments

            mAHValid = True
        End Sub

        Private Sub UpdateAppointmentHistory()
            If AHValid Then
                AHValid = False
                If TabControl.SelectedTab Is AHTab Then
                    LoadAppointmentHistory()
                End If
            End If
        End Sub

        Private Sub AHView_CustomDrawCell(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles AHView.CustomDrawCell
            If e.Column Is AHStatusColumn Then
                e.DisplayText = AppointmentHelper.GetAppointmentStatusString(AHView.GetDataRow(e.RowHandle))
            End If
        End Sub

        Private Sub AHView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles AHView.MouseDown
            If (e.Clicks > 1) And (e.Button = MouseButtons.Left) Then
                Dim hitInfo As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo = AHView.CalcHitInfo(New Point(e.X, e.Y))

                If hitInfo.RowHandle >= 0 Then
                    Dim row As DataRow = AHView.GetDataRow(hitInfo.RowHandle)

                    If Not row Is Nothing Then
                        AppointmentForm.OpenForm(row)
                    End If
                End If
            End If
        End Sub
#End Region

#Region " Life-Cycle Routines "
        Protected Overrides Sub DoSaving()
            If Not BirthDateEdit.DoValidate Then
                BirthDateEdit.DateTime = Now()
            End If
            Helpers.ClientHelper.UpdateClient(DataSource, Me)
        End Sub

        Protected Overrides Function CreateNewRow() As DataRow
            Return ClientHelper.CreateNewClient
        End Function

        Protected Overrides Sub OnDelete()
            Helpers.ClientHelper.DeleteClient(DataSource, Me)
        End Sub

#End Region

#Region " Preferenses & Configuration"
        Protected Overrides Sub LoadPreferences(ByVal pref As IPreferencesNode)
            MyBase.LoadPreferences(pref)

            Dim node As IPreferencesNode
            Dim ba As Byte()

            ' BHGrid
            node = pref.GetNodeForPath(BHGrid.Name)
            ba = node.GetByteArray("BHGrid", Nothing) : If Not ba Is Nothing Then BHView.RestoreLayoutFromStream(New MemoryStream(ba))
            ba = node.GetByteArray("BDGrid", Nothing) : If Not ba Is Nothing Then BDView.RestoreLayoutFromStream(New MemoryStream(ba))

            ' AHGrid
            node = pref.GetNodeForPath(AHGrid.Name)
            ba = node.GetByteArray("AHGrid", Nothing) : If Not ba Is Nothing Then AHView.RestoreLayoutFromStream(New MemoryStream(ba))
        End Sub

        Protected Overrides Sub SavePreferences(ByVal pref As IPreferencesNode)
            Dim node As IPreferencesNode
            Dim ms As MemoryStream

            ' BHGrid
            node = pref.GetNodeForPath(BHGrid.Name)
            ms = New MemoryStream : BHView.SaveLayoutToStream(ms) : node.Item("BHGrid") = ms.ToArray()
            ms = New MemoryStream : BDView.SaveLayoutToStream(ms) : node.Item("BDGrid") = ms.ToArray()

            ' AHGrid
            node = pref.GetNodeForPath(AHGrid.Name)
            ms = New MemoryStream : AHView.SaveLayoutToStream(ms) : node.Item("AHGrid") = ms.ToArray()

            MyBase.SavePreferences(pref)
        End Sub

        Protected Overrides Sub UpdateSecurityEditCommands()
            If DeleteBarItem.Enabled Then
                DeleteBarItem.Enabled = Security.CanDeleteClient
            End If
            SaveBarItem.Enabled = True
            SaveCloseBarItem.Enabled = True
            SaveNewBarItem.Enabled = True

            If Not Security.IsManager() Then
                TabControl.TabPages.Remove(BHTab)
                TabControl.SelectedIndex = 0
            End If
        End Sub

        Protected Overrides Sub OnApplicationEvent(ByVal sender As Object, ByVal e As Events.PhoenixEventArgs)
            Select Case e.EventCode
                Case PhoenixEventCode.ConfigurationChanged
                    UpdateConfiguration()
                Case PhoenixEventCode.BizRemoved
                    OnBizEvent(e)
                Case PhoenixEventCode.BizUpdated
                    OnBizEvent(e)
                Case PhoenixEventCode.BizAdded
                    OnBizEvent(e)
            End Select
        End Sub

        Private Sub OnBizEvent(ByVal e As Events.PhoenixEventArgs)
            If (TypeOf e.EventData Is DataSetAppointments.Appointment) And AHValid Then
                OnAppointmentEvent(e)
            ElseIf (TypeOf e.EventData Is DataSetBill.Bill) And BHValid Then
                OnBillEvent(e)
            End If
        End Sub

        Private Sub OnAppointmentEvent(ByVal e As Events.PhoenixEventArgs)
            Dim app As DataSetAppointments.Appointment = e.EventData
            Dim ds As DataSetAppointments.AppointmentsDataTable = AHGrid.DataSource

            If app.Table Is ds Then Exit Sub

            UpdateAppointmentHistory()
        End Sub

        Private Sub OnBillEvent(ByVal e As Events.PhoenixEventArgs)
            Dim bill As DataSetBill.Bill = e.EventData
            Dim ds As DataSetBill.BillsDataTable = BHGrid.DataSource

            If bill.Table Is ds Then Exit Sub
            If bill.ClientID <> DataSource.ClientID Then Exit Sub

            UpdateBillHistory()
        End Sub


        Private Sub UpdateConfiguration()
            BDIconRI.SmallImages = AppSharedComponents.ListImages
            BDIconColumn.MinWidth = BDIconRI.SmallImages.ImageSize.Width + AppIconColumnPadding

            AHIconRI.SmallImages = AppSharedComponents.ListImages
            AHIconColumn.MinWidth = AHIconRI.SmallImages.ImageSize.Width + AppIconColumnPadding
        End Sub

#End Region

    End Class

End Namespace
